package com.vhall.component.controller.rbac;


import com.vhall.component.controller.rbac.facade.RbacRoleFacade;
import com.vhall.component.entity.rbac.vo.*;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.service.rbac.RbacRoleAccessService;
import com.vhall.component.service.rbac.RbacRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;

import java.util.List;


/**
 * @author dalong
 * @date 2021-05-12 20:55
 */
@Api(tags = "RoleController", value = "角色")
@VhallComponent
@Slf4j
@TokenAuth
public class RbacRoleController implements RbacRoleFacade {

    @Autowired
    private RbacRoleAccessService roleAccessService;

    @Autowired
    private RbacRoleService roleService;


    @ApiOperation("增加角色权限")
    @Override
    public Boolean addAccess(@Validated RoleAddAccessReqVO reqVO) {
        return roleAccessService.batchCreate(reqVO);
    }

    @ApiOperation("删除角色权限")
    @Override
    public Boolean deleteAccess(@Validated RoleDeleteAccessReqVO reqVO) {
        return roleAccessService.batchDelete(reqVO);
    }

    @ApiOperation("获取应用角色列表")
    @Override
    public List<RoleVO> getListByApp(@Validated RoleGetListByAppReqVO reqVO) {
        return roleService.getRoleByApp(reqVO);
    }

    @ApiOperation("修改角色")
    @Override
    public Boolean update(@Validated RoleUpdateReqVO reqVO) {
        return roleService.update(reqVO);
    }

    @ApiOperation("创建角色")
    @Override
    public RoleVO create(@Validated RoleCreateReqVO reqVO) {
        return roleService.create(reqVO);
    }

    @ApiOperation("删除角色")
    @Override
    public Boolean delete(@Validated RoleDeleteReqVO reqVO) {
        return roleService.delete(reqVO);
    }

    @ApiOperation("获取角色权限")
    @Override
    public List<RoleInfoRspVO> info(@Validated RoleInfoReqVO reqVO) {
        return roleAccessService.getAccessListById(reqVO);
    }

    /**
     * 角色-编辑菜单权限
     *
     * @param vo
     * @return 返回值
     */
    @Override
    public Boolean editMenues(EditMenuesReqVO vo) {
        return roleService.editMenues(vo);
    }
}
